<%@ page contentType="text/html;charset=UTF-8" trimDirectiveWhitespaces="true" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<c:set var="extLibs" value="grid"/>
<sys:header title="报电量管理" extLibs="${extLibs}"/>
<div class="portlet box ${boxStyleColor}">
    <div class="portlet-title">
        <div class="caption"><i class="fa fa-coffee"></i> 报电量管理</div>
        <div class="actions">
            <a href="#" class="btn btn-default btn-sm" id="btnSearch" title="查询"><i class="fa fa-search"></i> 查询</a>
            <%--<shiro:hasPermission name="plan:elecPlan:edit">
                <a href="${ctx}/plan/elecPlan/form" class="btn btn-default btn-sm btnTool" title="新增报电量"><i class="fa fa-plus"></i> 新增</a>
            </shiro:hasPermission>--%>
            <a href="#" class="btn btn-default btn-sm" id="btnExport" title="导出"><i
                    class="fa fa-external-link"></i>导出</a>
        </div>
    </div>
    <div class="portlet-body list">
        <form:form id="searchForm" modelAttribute="elecPlan" action="${ctx}/plan/elecPlan/listData" method="post"
                   class="breadcrumb form-inline hide"
                   data-page-no="${page.pageNo}" data-page-size="${page.pageSize}" data-order-by="${page.orderBy}">
            <div class="form-group">
                <label class="control-label">企业名称：</label>
                <div class="input-inline">
                    <form:input path="btypeName" htmlEscape="false" maxlength="64"
                                class="form-control input-sm width-160"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label">时间：</label>
                <div class="input-inline">
                    <input id="yearAndMonth" name="yearAndMonth" type="text" readonly="readonly" maxlength="20"
                           class="form-control input-sm width-160"
                           value="${fns:formatDate(elecPlan.yearAndMonth, 'yyyy-MM')}"
                           onclick="WdatePicker({dateFmt:'yyyy-MM',isShowClear:false});"/>
                </div>
            </div>
            <div class="form-group" style="margin-left:10px;">
                <input class="btn btn-primary btn-sm" type="submit" value="查询"/>&nbsp;
                <input class="btn default btn-sm" type="reset" value="重置"/>
            </div>
        </form:form>
        <table id="dataGrid"></table>
        <div id="dataGridPage"></div>
    </div>
</div>
<sys:footer extLibs="${extLibs}"/>
<script type="text/javascript">
    // 初始化DataGrid对象
    $("#dataGrid").dataGrid({

        searchForm: $("#searchForm"), // 数据来源表单
        tabPageId: '${param.tabPageId}',// 当前页签编号

        // 设置数据表格列
        columnModel: [
            {
                header: '填报人名称',
                name: 'userName',
                index: 'c.user_name',
                width: 200,
                align: "center",
                frozen: true,
                formatter: function (val, obj, row, act) {
                    return '<a href="${ctx}/plan/elecPlan/form?id=' + row.id + '" class="btnList" data-title="填写收益">' + (val ? val : row.id) + '</a>';
                }
            },
            {header: '填报人手机号', name: 'phone', index: 'a.phone', width: 200, align: "center"},
            {header: '企业名称', name: 'btypeName', index: 'b.btype_name', width: 200, align: "center"},
            {header: '时间', name: 'yearAndMonth', index: 'a.year_and_month', width: 200, align: "center"},
            {header: '计划用电量', name: 'kwh', index: 'a.kwh', width: 200, align: "center"},
            {header: '收益', name: 'earnings', index: 'a.earnings', width: 120, align: "right"},
            {header: '创建时间', name: 'createDate', index: 'a.create_date', width: 200, align: "center"},
            {
                header: '操作',
                name: 'actions',
                width: 100,
                fixed: true,
                sortable: false,
                formatter: function (val, obj, row, act) {
                    var actions = [];//<shiro:hasPermission name="plan:elecPlan:edit">
                    if (row.status == Global.STATUS_NORMAL) {
                        actions.push('<a href="${ctx}/plan/elecPlan/form?id=' + row.id + '" class="btnList" title="编辑报电量"><i class="fa fa-pencil"></i></a>&nbsp;');
                        actions.push('<a href="${ctx}/plan/elecPlan/delete?id=' + row.id + '" class="btnList" title="删除该报电量" data-confirm="确认要删除该报电量吗？"><i class="fa fa-trash-o"></i></a>&nbsp;');
                    }//</shiro:hasPermission>
                    return actions.join('');
                }
            }
        ],
        ajaxSuccess: function (data) { // 加载成功后执行方法

        }
    });

    //导出
    $("#btnExport").click(function () {
        top.$.jBox.confirm("确认要导出数据吗？", "系统提示", function (v, h, f) {
            if (v == "ok") {
                ajaxDownload('${ctx}/plan/elecPlan/export',  decodeURIComponent($("#searchForm").serialize(),true));
            }
        }, {buttonsFocus: 1});
        top.$('.jbox-body .jbox-icon').css('top', '55px');
    });

    //文件下载
    function ajaxDownload(url, data, method) {
        // 获取url和data
        if (url && data) {
            // data 是 string 或者 array/object
            data = typeof data == 'string' ? data : jQuery.param(data);
            // 把参数组装成 form的 input
            var inputs = '';

            $.each(data.split('&'), function () {
                var pair = this.split('=');
                inputs += '<input type="hidden" name="' + pair[0] + '" value="'
                    + pair[1].replace('+', '') + '" />';
            });
            // request发送请求
            $('<form action="' + url + '" method="' + (method || 'post')
                + '" >' + inputs + '</form>').appendTo('body').submit().remove();
        }
    }
</script>